/**
 * 数据处理
 * @param {Array} datas
 * @param {Number} option.day: 数据区间
 * @param {String} option.type: 数据类型
 * @return {Array} 返回两个数据列
 */
export default function(datas) {
  let sh300 = []; // 沪深300
  let rzrqye = []; // 融资融券当日余额
  // 涨跌幅
  let zdf_threed = [];
  let zdf_fived = [];
  let zdf_tend = [];

  datas.forEach((item, i) => {
    sh300.push({ y: item.close_price, x: i, time: item.dim_date });
    rzrqye.push({ y: item.rzrqye, x: i, time: item.dim_date });
    zdf_fived.push({ y: item.zdf_fived, x: i, time: item.dim_date });
    zdf_tend.push({ y: item.zdf_tend, x: i, time: item.dim_date });
    zdf_threed.push({ y: item.zdf_threed, x: i, time: item.dim_date });
  });

  // 沪深300涨跌幅添加颜色
  // 大于0是红色, 小于0是绿色
  const addColor = (item) => {
    item.color = item.y > 0 ? "#FD4848" : "#08751c";
    return item;
  };
  zdf_threed = zdf_threed.map(addColor);
  zdf_fived = zdf_fived.map(addColor);
  zdf_tend = zdf_tend.map(addColor);

  let dataTable = {
    "1-rzrqye": [
      {
        data: sh300,
        type: "spline",
        name: "沪深300指数",
        color: "#EA2827",
      },
      {
        data: rzrqye,
        type: "spline",
        name: "两融余额",
        yAxis: 1,
        color: "#2C7EFF",
      },
    ],
  };

  let key = `1-rzrqye`;
  console.log("图表数据字段值", key);
  if (!dataTable[key]) {
    throw new Error(`未匹配到数据列:${key}`);
  }

  return dataTable[key];
}
